// OGoMojo
// Whitemice.MOGI.RPC2.Resource
// License: LGPL
// Copyright: Whitemice Consulting, 2006
// Author(s): Adam Tauno Williams (awilliam@whitemice.org)
using System;
using System.Globalization;
using Whitemice.MOGI;
using CookComputing.XmlRpc;

namespace Whitemice.MOGI.RPC2 
{
	/// \brief Implementation of IResource
	public class Resource : Whitemice.MOGI.RPC2.Document, IResource 
	{
		/// \brief Constructor
		/// \param document
		/// \param server
		public Resource(XmlRpcStruct document, Server server)
		 : base(document, server) 
		{
			server.Log.Debug("Resource(...)");
		}
		
		/// \brief Common name of the resource
		public string Description
		{
			get { return (string)document["name"]; }
			set { document["name"] = value; }
		}
		
		/// \brief Unique name of document
		public override string Name
		{
			get { return "Document/Resource/" + Number; }
		}
		
		/// \brief E-Mail property
		public string EMail
		{
			get	{ return (string)document["email"]; }
			set	{ document["email"] = value; }
		}
		
		/// \brief Alert e-mail subject property
		public string Subject
		{
			get	{ return (string)document["emailSubject"];	}
			set	{ document["emailSubject"] = value;	}
		}
		
		/// \brief Category property
		public string Category
		{
			get	{ return (string)document["category"];	}
			set
			{
				if (server.Search("Category/Resource/=all").Contains(value))
					document["category"] = value;
					else throw new InvalidCategoryException();
			}
		}
	}
}